﻿<UserControl x:Name="root" x:Class="GlyphEditingArea"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:c="clr-namespace:InkType"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="400">
    <FrameworkElement.CommandBindings>
        <CommandBinding x:Name="UndoCommand" Command="ApplicationCommands.Undo"
                        CanExecute="UndoCommand_CanExecute" Executed="UndoCommand_Executed"/>
        <CommandBinding x:Name="RedoCommand" Command="ApplicationCommands.Redo"
                        CanExecute="RedoCommand_CanExecute" Executed="RedoCommand_Executed"/>
        <CommandBinding x:Name="ClearCommand" Command="c:GlyphCanvasCommands.ClearCommand"
                        CanExecute="ClearCommand_CanExecute" Executed="ClearCommand_Executed"/>
        <CommandBinding x:Name="ChangeEditModeCommand" Command="c:GlyphCanvasCommands.ChangeEditModeCommand"
                        CanExecute="ChangeEditModeCommand_CanExecute" Executed="ChangeEditModeCommand_Executed"/>
    </FrameworkElement.CommandBindings>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <ToolBar>
            <Button Content="Undo" Command="ApplicationCommands.Undo" CommandTarget="{x:Reference canvas}"/>
            <Button Content="Redo" Command="ApplicationCommands.Redo" CommandTarget="{x:Reference canvas}"/>
            <Separator/>
            <Button Content="Clear" Command="c:GlyphCanvasCommands.ClearCommand" CommandTarget="{x:Reference canvas}"/>
            <Separator/>
            <RadioButton Content="Pen" IsChecked="{Binding ElementName=canvas, Path=EditingMode, Mode=OneWay, Converter={x:Static c:ParamEqualityConverter.Instance}, ConverterParameter={x:Static InkCanvasEditingMode.Ink}}"
                         Command="c:GlyphCanvasCommands.ChangeEditModeCommand" CommandParameter="{x:Static InkCanvasEditingMode.Ink}" CommandTarget="{x:Reference canvas}"/>
            <RadioButton Content="Selector" IsChecked="{Binding ElementName=canvas, Path=EditingMode, Mode=OneWay, Converter={x:Static c:ParamEqualityConverter.Instance}, ConverterParameter={x:Static InkCanvasEditingMode.Select}}"
                         Command="c:GlyphCanvasCommands.ChangeEditModeCommand" CommandParameter="{x:Static InkCanvasEditingMode.Select}" CommandTarget="{x:Reference canvas}"/>
            <RadioButton Content="Eraser-P" IsChecked="{Binding ElementName=canvas, Path=EditingMode, Mode=OneWay, Converter={x:Static c:ParamEqualityConverter.Instance}, ConverterParameter={x:Static InkCanvasEditingMode.EraseByPoint}}"
                         Command="c:GlyphCanvasCommands.ChangeEditModeCommand" CommandParameter="{x:Static InkCanvasEditingMode.EraseByPoint}" CommandTarget="{x:Reference canvas}"/>
            <RadioButton Content="Eraser-S" IsChecked="{Binding ElementName=canvas, Path=EditingMode, Mode=OneWay, Converter={x:Static c:ParamEqualityConverter.Instance}, ConverterParameter={x:Static InkCanvasEditingMode.EraseByStroke}}"
                         Command="c:GlyphCanvasCommands.ChangeEditModeCommand" CommandParameter="{x:Static InkCanvasEditingMode.EraseByStroke}" CommandTarget="{x:Reference canvas}"/>
        </ToolBar>
        <c:GlyphCanvasScrollViewer Grid.Row="1">
            <Grid>
                <FrameworkElement.LayoutTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="{Binding ElementName=root, Path=Zoom}" ScaleY="{Binding ElementName=root, Path=Zoom}"/>
                        <SkewTransform/>
                        <RotateTransform Angle="{Binding ElementName=root, Path=Rotation}"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </FrameworkElement.LayoutTransform>
                <c:GlyphMetricsCanvas Zoom="{Binding ElementName=root, Path=Zoom}"/>
                <c:GlyphCanvas x:Name="canvas" Background="Transparent" Strokes="{Binding StrokeCollection}" GlyphWidth="{Binding GlyphWidth}"
                               DefaultDrawingAttributes="{Binding ElementName=root, Path=DrawingAttributes}"/>
            </Grid>
        </c:GlyphCanvasScrollViewer>
    </Grid>
</UserControl>
